import * as types from '../type'
import local from '@/services/local'
import setting from '@/config/setting.js'
// initial state
const state = {
  user: {}
}

// getters
const getters = {
  getuser: state => state.user,
  getusername: function (state) {
    return state.user ? state.user.username : ''
  },
  getuserid: state => state.user ? state.user.userid : 0
}

// actions
const actions = {
  setUser ({ commit }) {
    commit(types.SET_USER, { users })
  }
}

// mutations
const mutations = {
  [types.SET_USER] (state, { user }) {
    state.user = user
    local.setItem (setting.userToken, user)
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
